package com.cm309.hospital.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cm309.hospital.dao.DoctorDao;
import com.cm309.hospital.dao.PatientDao;
import com.cm309.hospital.dao.SubjectDao;
import com.cm309.hospital.model.Patient;

@WebServlet("/patientEnq2.do")
public class PatientEnq2 extends HttpServlet{

//	@Override
//	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
//			throws ServletException, IOException {
//		// TODO Auto-generated method stub
////		super.doGet(req, resp);
//		
//		List doctors = new ArrayList();
//		DoctorDao doctorDao = new DoctorDao();
//		doctors = doctorDao.queryAll();
//		req.setAttribute("doctors",doctors);
//		req.getRequestDispatcher("view/patientEnq.jsp").forward(req, resp);
//	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String subject_id = req.getParameter("subject_id");
		System.out.println("subject_id :" +subject_id);		
		
		String patient_id = req.getParameter("patient_id");
		
		Patient patient = new Patient();
		PatientDao patientDao = new PatientDao();
		patient = patientDao.querySingle(patient_id);
		System.out.println("3");		

		
			req.setAttribute("patient",patient);
			
			List subjects = new ArrayList();
			SubjectDao subjectDao = new SubjectDao();
			subjects = subjectDao.queryAll();
			req.setAttribute("subjects",subjects);
					
			req.setAttribute("subject_id", subject_id);
			req.setAttribute("subject",subjectDao.querySingle(subject_id));			

			List doctors = new ArrayList();
			DoctorDao doctorDao = new DoctorDao();
			doctors = doctorDao.queryDoctorsBySubject(subject_id);
System.out.println("size of doctors :"+doctors.size());			
			req.setAttribute("doctors",doctors);

			
			
			
			req.getRequestDispatcher("view/patientDetail2.jsp").forward(req, resp);
//		}
//		else
//		{
//			req.getRequestDispatcher("mainPage.do").forward(req,resp);
//		}
	}


}
